﻿// =====================================================================
//
//  This file is part of the Microsoft Dynamics CRM SDK code samples.
//
//  Copyright (C) Microsoft Corporation.  All rights reserved.
//
//  This source code is intended only as a supplement to Microsoft
//  Development Tools and/or on-line documentation.  See these other
//  materials for detailed information regarding Microsoft code samples.
//
//  THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
//  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//  PARTICULAR PURPOSE.
//
// =====================================================================
using System.Runtime.Serialization;

namespace Microsoft.Xrm.Sdk.Metadata
{
	[DataContract(Name = "ManagedPropertyAttributeMetadata", Namespace = XmlNamespaces.V5.Metadata)]
	public sealed class ManagedPropertyAttributeMetadata : AttributeMetadata
	{
		#region Constants
		public const int EmptyParentComponentType = 0;
		#endregion

		#region Fields
		private string _managedPropertyLogicalName;
		private int? _parentComponentType;
		private string _parentAttributeName;

		// currently all business entity managed properties are all Booleans
		private AttributeTypeCode _typeCode = AttributeTypeCode.Boolean;
		#endregion

		#region Constructors
		public ManagedPropertyAttributeMetadata()
			: this(null)
		{
		}

		public ManagedPropertyAttributeMetadata(string schemaName)
			: base(AttributeTypeCode.ManagedProperty, schemaName)
		{
		}
		#endregion

		#region Properties

		[DataMember]
		public string ManagedPropertyLogicalName
		{
			get { return this._managedPropertyLogicalName; }
			internal set { this._managedPropertyLogicalName = value; }
		}

		[DataMember]
		public int? ParentComponentType
		{
			get { return this._parentComponentType; }
			internal set { this._parentComponentType = value; }
		}

		[DataMember]
		public string ParentAttributeName
		{
			get { return this._parentAttributeName; }
			internal set { this._parentAttributeName = value; }
		}

		[DataMember]
		public AttributeTypeCode ValueAttributeTypeCode
		{
			get { return this._typeCode; }
			internal set { this._typeCode = value; }
		}
		#endregion
	}
}
